var _md5 = null;
try {
	_md5 = Components.classes['@mozilla.org/security/hash;1'].createInstance(Components.interfaces.nsICryptoHash);
} catch (err) {
	Components.utils.reportError(err);
}
var md5 = function(str) {
	if (null == _md5) {
		return '';
	}
	
	// Build array of character codes to MD5
	var arr = [];
	var ii = str.length;
	for (var i = 0; i < ii; ++i) {
		arr.push(str.charCodeAt(i));
	}
	_md5.init(Ci.nsICryptoHash.MD5);
	_md5.update(arr, arr.length);
	var hash = _md5.finish(false);

	// Unpack the binary data bin2hex style
	var ascii = [];
	ii = hash.length;
	for (var i = 0; i < ii; ++i) {
		var c = hash.charCodeAt(i);
		var ones = c % 16;
		var tens = c >> 4;
		ascii.push(String.fromCharCode(tens + (tens > 9 ? 87 : 48)) +
			String.fromCharCode(ones + (ones > 9 ? 87 : 48)));
	}

	return ascii.join('');
};